home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 6.2 KB | 261 lines | [TEXT/KAHL] |
- // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // • Program: FrameAnim
- // • File: Events.c
- // •
- // • Copyright © 1993 by Scott B. Steinman, O.D., Ph.D. All Rights Reserved.
- // ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- #include "FrameAnim.h"
-
- // • ------------------ External Globals ----------------------------------
-
- extern CWindowPtr gMainWindow; // • From Main.c file
- extern EventRecord gEvent; // • From Main.c file
- extern Flags gFlags; // • From Main.c file
-
- // • ------------------ Static Functions ----------------------------------
-
- static void ActivateEvent( void );
- static void HandleAppleMenu( const short );
- static void HandleFileMenu( const short );
- static void HandleAnimMenu( const short );
- static void MouseEvent( void );
- static void ProcessMenus( const long );
- static void UpDateEvent( void );
-
- // • ------------------ Handle Menu Selections ----------------------------
-
- static void
- ProcessMenus( const long menuChoice )
- // •
- // • Control center for menus.
- {
- short menuNo, itemNo;
-
-
- if (menuChoice != 0) {
- menuNo = HiWord( menuChoice ); // • Passed from Mouse Handler.
- itemNo = LoWord( menuChoice );
- switch( menuNo ) {
- case kAppleID: HandleAppleMenu( itemNo ); break;
- case kFileID: HandleFileMenu( itemNo ); break;
- case kAnimID: HandleAnimMenu( itemNo ); break;
- }
- ResetWindBkgnd();
- HiliteMenu( 0 ); // • Turn off menu highlighting.
- }
- }
-
- // • ------------------ Handle Apple Menu Selections ----------------------
-
- static void
- HandleAppleMenu( const short itemNo )
- // •
- // • Control center for Apple menu.
- {
- short bogus, deskAcc;
- Str255 nameHolder; // • Holds the name of desired DA
-
-
- switch( itemNo ) {
- case kAboutAnimItem:
- bogus = Alert( kAboutAlertID, NullPointer );
- break;
- default: // • This makes the desk accesories available.
- GetItem( GetMHandle( kAppleID ), itemNo, &nameHolder );
- deskAcc = OpenDeskAcc( &nameHolder );
- break;
- }
- }
-
- // • ------------------ Handle File Menu Selections -----------------------
-
- static void
- HandleFileMenu( const short itemNo )
- // •
- // • This is the control center for the File menu.
- {
- switch( itemNo ) {
- case kOpenFilmItem:
- OpenFilm();
- if (gFlags.cancel == false) {
- EnableItem( GetMHandle( kAnimID ), kPlayItem );
- EnableItem( GetMHandle( kFileID ), kSaveFilmItem );
- }
- break;
- case kSaveFilmItem:
- SaveFilm();
- break;
- // • ------- Blank Line
- case kQuitItem:
- gFlags.done = true;
- break;
- }
- }
-
- // • ------------------ Handle Animation Menu Selections ------------------
-
- static void
- HandleAnimMenu( const short itemNo )
- // •
- // • Control center for Option menu.
- {
- switch( itemNo ) {
- case kPlayItem:
- PlayFilm();
- break;
- // • --------- Blank Line
- case kFrameSzItem:
- FrameSzDlg();
- break;
- case kGrayItem:
- GrayDlg();
- break;
- // • --------- Blank Line
- case kFilmItem:
- FilmDlg();
- if (gFlags.cancel == false) {
- DoFilm();
- EnableItem( GetMHandle( kAnimID ), kPlayItem );
- EnableItem( GetMHandle( kFileID ), kSaveFilmItem );
- }
- gFlags.cancel = false; // • Reset cancel status to false for next time
- break;
- }
- }
-
- // • ------------------ Mouse Event Handler -------------------------------
-
- static void
- MouseEvent( void )
- // •
- // • Keep track of mouse activity.
- {
- WindowPtr windowPointedTo = NullPointer;
- Point mouseLoc;
- long menuChoice;
- short windowPart, location;
-
-
- mouseLoc = gEvent.where;
- windowPart = FindWindow( mouseLoc, &windowPointedTo );
- switch( windowPart ) {
- case inMenuBar:
- menuChoice = MenuSelect( mouseLoc );
- ProcessMenus( menuChoice );
- break;
- case inSysWindow:
- SystemClick( &gEvent, windowPointedTo );
- break;
- case inContent:
- if (windowPointedTo != FrontWindow())
- SelectWindow( windowPointedTo );
- else {
- SetPort( windowPointedTo );
- PmForeColor( kPalBkgnd );
- PaintRect( &(windowPointedTo->portRect) );
- ResetForeAndBackColors();
- }
- break;
- }
- }
-
- // • ------------------ Key Down Event Handler ----------------------------
-
- static void
- KeyEvent( void )
- // •
- // • Controls the input through keyboard.
- {
- char charCode;
-
- charCode = gEvent.message & charCodeMask;
- if (BitAnd( gEvent.modifiers, cmdKey ) != 0) // • Command Key Pressed
- ProcessMenus( MenuKey( charCode ) ); // • Process "/?" combinations.
- }
-
- // • ------------------ Activate Event Handler ----------------------------
-
- static void
- ActivateEvent( void )
- // •
- // • This is Generic "make things happen" procedure.
- {
- WindowPtr targetWindow;
-
-
- targetWindow = (WindowPtr) gEvent.message;
- if (gEvent.modifiers & 1) { // • Window needs to be activated
- SetPort( targetWindow );
- ResetWindBkgnd();
- }
- else {
- ; // • Deactivate window or whatever
- }
- }
-
- // • ------------------ Update Event Handler ------------------------------
-
- static void
- UpDateEvent( void )
- // •
- // • Handles update events.
- {
- GDHandle currentDev = NullHandle;
- CGrafPtr currentPort = NullPointer,
- updateWindow;
-
- GetGWorld( ¤tPort, ¤tDev ); // • Save current port & device
-
- updateWindow = (CGrafPtr) gEvent.message;
- SetPort( updateWindow );
- BeginUpdate( updateWindow );
- ResetWindBkgnd();
- EndUpdate( updateWindow );
-
- SetGWorld( currentPort, currentDev ); // • Reset port & device
- }
-
- // • ------------------ Reset Window Background Color ---------------------
-
- void
- ResetWindBkgnd( void )
- // •
- // • The window background color must sometimes be reset
- // • after a dialog box presentation.
- {
- PmBackColor( kPalBkgnd );
- EraseRect( &(gMainWindow->portRect) ); // • Clear the area completely
- ResetForeAndBackColors();
- }
-
- // • ------------------ Main Event Loop -----------------------------------
-
- void
- MainEventLoop( void )
- // •
- // • Event dispatch routine.
- {
- do {
- WaitNextEvent( everyEvent, &gEvent, kMinSleep, kNilMouseRegion );
- switch( gEvent.what ) {
- case keyDown:
- KeyEvent();
- break;
- case activateEvt:
- ActivateEvent();
- break;
- case updateEvt:
- UpDateEvent();
- break;
- case mouseDown:
- MouseEvent();
- break;
- case nullEvent:
- default:
- break;
- }
- } while ( ! gFlags.done ); // • Until quit is chosen.
- }
-
-